----------------------------------------------
-- infMassResser
----------------------------------------------

local Frame = CreateFrame("Frame")

SLASH_INFMASSRESSER1 = "/release"

SlashCmdList["INFMASSRESSER"] = function(msg, editBox)
	RepopMe();
end

function IsInHeroicRaidDungeon()
	local InInstance, InstanceType = IsInInstance()
	local _, _, diff = GetInstanceInfo()
	if IsInRaid() and InInstance and InstanceType == "raid" and (diff == 5 or diff == 6) then
		return true
	end
	return false
end

StaticPopupDialogs["DEATH"] = {
	text = DEATH_RELEASE_TIMER,
	button1 = DEATH_RELEASE,
	button2 = USE_SOULSTONE,
	OnShow = function(self)
		self.timeleft = GetReleaseTimeRemaining();
		local text = HasSoulstone();
		if (text) then
			self.button2:SetText(text);
		end
		if (self.timeleft == -1) then
			self.text:SetText(DEATH_RELEASE_NOTIMER);
		end
	end,
	OnAccept = function(self)
		RepopMe();
	end,
	OnCancel = function(self, data, reason)
		if reason == "override" then
			return;
		end
		if reason == "timeout" then
			return;
		end
		if reason == "clicked" then
			if HasSoulstone() then
				UseSoulstone();
			else
				RepopMe();
			end
		end
	end,
	OnUpdate = function(self, elapsed)
		if IsFalling() and not IsOutOfBounds() then
			self.button1:Disable();
			self.button2:Disable();
		elseif HasSoulstone() then
			self.button1:Disable();
			self.button2:Enable();
		elseif IsInHeroicRaidDungeon() and not HasSoulstone() then
			if not UnitDebuff("player", (GetSpellInfo(95223))) then
				self.button1:Disable();
				self.button2:Disable();
				self.text:SetText("You have NO mass ress debuff, check for mass ress.")
			elseif UnitDebuff("player", (GetSpellInfo(95223))) then
				if ((select(7, UnitDebuff("player", (GetSpellInfo(95223))))) - GetTime()) >= 60 then
					self.button1:Enable();
					self.button2:Disable();
					self.text:SetText("You have MORE than one minute left on mass ress debuff.")
				else
					self.button1:Disable();
					self.button2:Disable();
					self.text:SetText("You have LESS than one minute left on mass ress debuff.")
				end
			end
		end
	end,
	DisplayButton2 = function(self)
		return HasSoulstone();
	end,
	timeout = 0,
	whileDead = 1,
	preferredIndex = 3,
	interruptCinematic = 1,
	notClosableByLogout = 1,
	cancels = "RECOVER_CORPSE"
};

